This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat(vitest-environment-nuxt): allow mocking imports within setup files #274
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
huang-julien
commented
Jul 24, 2023
// if not, the module won't be mocked | ||
if(shouldPrependMockHoist) { | ||
importPathsList.forEach((p) => { | ||
s.append( `\n import ${JSON.stringify(p)};\n`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to keep triggering vitest mock without importing the module ?
danielroe
changed the title
feat(vitest-environnement-nuxt): allow mocking imports within setup files
feat(vitest-environment-nuxt): allow mocking imports within setup files
Jul 24, 2023
hmmm... that's strange i can't reproduce the issue locally |
This reverts commit a090d18.
danielroe
approved these changes
Aug 14, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi 👋
This PR allows mocking imports within setup files.
Currently if we can only use
mockNuxtImport
either within the setup file or within the test file.The idea behind this PR is to use the new
vi.hoisted
from vitest 0.31 to set globally a__NUXT_VITEST_MOCKS
variable which would contains all imports (mocked or not).mockNuxtImport
will instead of returning the module modified, assign the module within the__NUXT_VITEST_MOCKS
variable, modify the mocked import and return__NUXT_VITEST_MOCKS